home *** CD-ROM | disk | FTP | other *** search
- /*
-
- SolveRubiksCube
- Copyright (c) 1994 J Robert Boonstra
-
- */
-
- #pragma options(honor_register,assign_registers)
-
- #include "rubik.h"
- #include "transform.h"
-
- Boolean SolveBottomCorners(register RubiksCube *rub)
- {
- short loopCount;
-
- /**********************************************************
- *
- * STEP 4: Move corner cubes in bottom layer into position.
- * (but not necessarily the correct orientation)
- *
- *********************************************************/
- if ( CornerEquals(D,L,B,D,R,B) ) { D3;
- } else if ( CornerEquals(D,L,F,D,R,B) ) { D2;
- } else if ( CornerEquals(D,R,F,D,R,B) ) { D1;
- }
- /*
- * Given that one corner (DRB) is in the correct position,
- * move the other corners into the correct position. There
- * are (according to Taylor), 4 possibilities, clockwise
- * rotation of the three other corners, counterclockwise
- * rotation, horizontal exchange (of two), or diagonal
- * exchange of two.
- */
- if ( CornerCorrect(D,R,F) ) { /* DRF correct */
- if ( CornerCorrect(D,L,F) ) { /* DLF correct */
- ;
- } else {
- R1D3L3D1R3D3L1D2; /* Exchange DLF and DLB */
- }
- } else {
- if ( CornerCorrect(D,L,F) ) {
- D1B1D1R1D3R3B3; /* Exchange DLB and DRF */
- } else {
- if ( CornerCorrect(D,L,B) ) {
- B1D3F3D1B3D3F1D2; /* Exchange DLF and DRF */
- } else {
- if ( CornerEquals(D,L,B,D,L,F) ) {
- L3D1R1D3L1D1R3D3; /* DLF<-DLB<-DRF */
- } else {
- D1R1D3L3D1R3D3L1; /* DLF<-DRF<-DLB */
- }
- }
- }
- }
- /**********************************************************
- *
- * STEP 5: Twist corners in bottom layer.
- *
- *********************************************************/
- loopCount=0;
- do {
- if (++loopCount > 16) return (false);
- /*
- * At this point, all the corners in the bottom layer are
- * in the correct positions, but perhaps not in the
- * correct orientation.
- */
- if (DLF_F == F && DRF_R == R &&
- DRB_B == B && DLB_L == L)
- break;
- /*
- * Not all of the corners are in the correct orientation.
- * The cube has the property that the "twist" of corner
- * cubes sums to zero, meaning that we have one of the
- * following cases:
- * -- 3 cubes needing a clockwise twist
- * -- 2 cubes needing a clockwise twist and
- * 2 needing a counterclockwise twist
- * -- 1 cube needing a counterclockwise twist and
- * 1 needing a clockwise twist
- * -- 3 cubes needing a counterclockwise twist
- * The operators used in this cube solution twist one
- * corner clockwise and one counterclockwise.
- */
- if (DLF_F == D) { /* DLF needs a clockwise twist */
- L3U1L1F1U1F3;
- /*
- * Find a cube that needing a counterclockwise turn.
- */
- if (DLB_B == D) {
- LabD1F1U3F3L3U3L1D3:
- D1F1U3F3L3U3L1D3;
- } else if (DRB_R == D) {
- D2F1U3F3L3U3L1D2;
- } else if (DRF_F == D) {
- LabD3F1U3F3L3U3L1D1:
- D3F1U3F3L3U3L1D1;
- } else { /* No counterclockwise turn is needed,
- so we make one arbitrarily */
- if (DLB_D != D) {
- goto LabD1F1U3F3L3U3L1D3;
- } else {
- goto LabD3F1U3F3L3U3L1D1;
- }
- }
- } else if (DRF_R == D) {/*DRF needs a clockwise twist*/
- F3U1F1R1U1R3;
- if (DLF_L == D) {
- LabD1R1U3R3F3U3F1D3:
- D1R1U3R3F3U3F1D3;
- } else if (DLB_B == D) {
- D2R1U3R3F3U3F1D2;
- } else if (DRB_R == D) {
- LabD3R1U3R3F3U3F1D1:
- D3R1U3R3F3U3F1D1;
- } else { /* No counterclockwise turn is needed,
- so we make one arbitrarily */
- if (DLF_D != D) {
- goto LabD1R1U3R3F3U3F1D3;
- } else {
- goto LabD3R1U3R3F3U3F1D1;
- }
- }
- } else if (DRB_B == D) {/*DRB needs a clockwise twist*/
- R3U1R1B1U1B3;
- if (DRF_F == D) {
- LabD1B1U3B3R3U3R1D3:
- D1B1U3B3R3U3R1D3;
- } else if (DLF_L == D) {
- D2B1U3B3R3U3R1D2;
- } else if (DLB_B == D) {
- LabD3B1U3B3R3U3R1D1:
- D3B1U3B3R3U3R1D1;
- } else { /* No counterclockwise turn is needed,
- so we make one arbitrarily */
- if (DRF_D != D) {
- goto LabD1B1U3B3R3U3R1D3;
- } else {
- goto LabD3B1U3B3R3U3R1D1;
- }
- }
- } else if (DLB_L == D) {/*DLB needs a clockwise twist*/
- B3U1B1L1U1L3;
- if (DRB_R == D) {
- LabD1L1U3L3B3U3B1D3:
- D1L1U3L3B3U3B1D3;
- } else if (DRF_F == D) {
- D2L1U3L3B3U3B1D2;
- } else if (DLF_L == D) {
- LabD3L1U3L3B3U3B1D1:
- D3L1U3L3B3U3B1D1;
- } else { /* No counterclockwise turn is needed,
- so we make one arbitrarily */
- if (DRB_D != D) {
- goto LabD1L1U3L3B3U3B1D3;
- } else {
- goto LabD3L1U3L3B3U3B1D1;
- }
- }
- } else {
- /*
- * There are no corner cubes that need a clockwise twist.
- * So there must be 3 needing a counterclockwise twist.
- * We twist one clockwise and one counterclockwise.
- */
- if (DLF_F != F) {
- L3U1L1F1U1F3D1F1U3F3L3U3L1D3;
- } else {
- F3U1F1R1U1R3D1R1U3R3F3U3F1D3;
- }
- }
- } while(true);
- return (true);
- }
-